﻿Public Class WorkingStateColorConverter
    Implements IValueConverter

    Public Function Convert(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert
        If TypeOf (value) Is WorkingState Then
            Dim ws = DirectCast(value, WorkingState)
            Select Case ws
                Case WorkingState.NotRunning
                    Return Application.Current.Resources("BrushNotRunning")
                Case WorkingState.AllFine
                    Return Application.Current.Resources("BrushAllFine")
                Case WorkingState.AllDown
                    Return Application.Current.Resources("BrushAllDown")
                Case WorkingState.PartialFine
                    Return Application.Current.Resources("BrushPartialFine")
            End Select
        End If
        Return Application.Current.Resources("BrushNotRunning")
    End Function

    Public Function ConvertBack(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack
        If TypeOf (value) Is Color Then
            Dim c = DirectCast(value, Color)
            If c.G = 160 Then Return WorkingState.AllFine
            If c.R = 160 Then Return WorkingState.AllDown
            If c.G = 221 AndAlso c.R = 221 Then Return WorkingState.PartialFine
        End If
        Return WorkingState.NotRunning
    End Function
End Class
